package com.youan.serve.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.youan.serve.controller.swagger.SyscodeDetailControllerSwagger;
import com.youan.serve.service.ISyscodeDetailService;
import com.youan.serve.dao.domain.SyscodeDetail;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;




import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author auto_code
 * @since 2020-02-29
 */
@Controller
@RequestMapping("/syscodeDetail")
public class SyscodeDetailController implements SyscodeDetailControllerSwagger{
    @Autowired
    private ISyscodeDetailService syscodeDetailService;

    @Override
    @PostMapping("/syscodeDetail")
    public SyscodeDetail addSyscodeDetail(SyscodeDetail syscodeDetail){
        syscodeDetail.setDetailId(UUID.randomUUID().toString().replaceAll("-", ""));
        syscodeDetailService.save(syscodeDetail);
        return syscodeDetail;
    }

    @Override
    @PutMapping("/syscodeDetail")
    public SyscodeDetail updateSyscodeDetail(SyscodeDetail syscodeDetail){
        syscodeDetailService.updateById(syscodeDetail);
        return syscodeDetail;
    }

    @Override
    @GetMapping("/syscodeDetails")
    public List<SyscodeDetail> selectAllSyscodeDetail(){
        return syscodeDetailService.list();
    }

    @Override
    @DeleteMapping("/syscodeDetail/{detailId}")
    public void deleteSyscodeDetailByDetailId(@PathVariable String detailId){
        syscodeDetailService.removeById(detailId);
    }
    @Override
    @GetMapping("/syscodeDetail/{detailId}")
    public SyscodeDetail selectSyscodeDetailByDetailId(@PathVariable String detailId){
        return syscodeDetailService.getById(detailId);
    }

    @Override
    @GetMapping("/getSyscodeDetailsBySysCodeId/{sysCodeId}")
    public List<SyscodeDetail> getSyscodeDetailsBySysCodeId(@PathVariable String sysCodeId) {
        return syscodeDetailService.list(new LambdaQueryWrapper<SyscodeDetail>()
                .eq(SyscodeDetail::getSysCodeId, sysCodeId));
    }
}

